const express = require('express')
const router = express.Router()
//express.Router()

let mwAll = (req, res, next) => {
    console.log('这是router全局中间件')
    next()
}

let mw1 = (req, res, next) => {
    console.log('这是router局部中间件1')
    next()
}

let mw2 = (req, res, next) => {
    console.log('这是router局部中间件2')
    next()
}

router.use(mwAll)

router.get('/', [mw1, mw2], (req, res) => {
    res.send({
        name: '/',
        type: 'get',
        msg: 'get / 路由'
    })
})

router.get('/home', (req, res) => {
    res.send({
        name: '/home',
        type: 'get',
        msg: 'get /home 路由'
    })
})

router.post('/', [mw1, mw2], (req, res) => {
    res.send({
        name: '/',
        type: 'post',
        msg: 'post / 路由'
    })
})

router.post('/home', (req, res) => {
    res.send({
        name: '/home',
        type: 'post',
        msg: 'post /home 路由'
    })
})

module.exports = router